package com.summer.framework.admin.mq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @auther: 杨杰
 * @date: 2019/2/22 11:09
 * @description: exchange到queue成功, 则不回调return
 * exchange到queue失败,则回调return(需设置mandatory=true,否则不回回调,消息就丢了)
 */
@Slf4j
public class MsgReturnCallBack implements RabbitTemplate.ReturnCallback {

    @Override
    public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        String msgJson = new String(message.getBody());
        log.info("Returned Message：" + msgJson);
        //rabbitTemplate.send(message);
    }
}
